package com.shujia.wyh.day06.ketang;


class Animal3 {
    public void eat() {
        System.out.println("吃");
    }
}

class Dog3 extends Animal3 {
    @Override
    public void eat() {
        System.out.println("🐕吃🥩");
    }

    public void lookDoor() {
        System.out.println("看门");
    }
}

class Cat3 extends Animal3{
    @Override
    public void eat() {
        System.out.println("猫吃🐟");
    }

    public void pashu(){
        System.out.println("爬树");
    }
}

public class AnimalDemo2 {
    public static void main(String[] args) {
        Animal3 a = new Dog3();
        a.eat();
        //向下转型
        Dog3 d = (Dog3) a;
        d.eat();
        d.lookDoor();

        Animal3 a2 = new Cat3();
        a2.eat();
        //向下转型
//        Cat3 c = (Cat3) a2;
//        c.eat();
//        c.pashu();
        Dog3 d3 = (Dog3) a2; //ClassCastException 类型转换异常
        d3.eat();
        d3.lookDoor();
    }
}
